﻿using EPiAbstractions.Community.MyPage;
using EPiServer.Common.Security;
using EPiServer.Community.Blog;
using EPiServer.Community.MyPage;
using JoelAbrahamsson.MetaWeblog;
using Moq;
using StructureMap.AutoMocking;
using Xunit;

namespace JoelAbrahamsson.BlogExtensions.Tests.BlogProviderTests
{
    public class GetUsersBlogsTests
    {
        [Fact]
        public void GetUsersBlogs_ReturnsUsersMyPageBlog()
        {
            IUser user = new Mock<IUser>().Object;
            Mock<Blog> fakeMyPageBlog = new Mock<Blog>();
            fakeMyPageBlog.Setup(blog => blog.ID).Returns(1);
            Mock<MyPage> fakeMyPage = new Mock<MyPage>();
            fakeMyPage.Setup(myPage => myPage.Blog).Returns(fakeMyPageBlog.Object);
            MoqAutoMocker<BlogProvider> blogProviderAutoMocker = new MoqAutoMocker<BlogProvider>();
            Mock<IMyPageHandlerFacade> fakeMyPageHandlerFacade = Mock.Get(blogProviderAutoMocker.Get<IMyPageHandlerFacade>());
            fakeMyPageHandlerFacade.Setup(handler => handler.GetMyPage(user)).Returns(fakeMyPage.Object);

            BlogInfo[] returnedBlogs = blogProviderAutoMocker.ClassUnderTest.GetUsersBlogs(user);

            Assert.NotNull(returnedBlogs);
            Assert.Equal<string>(fakeMyPageBlog.Object.ID.ToString(), returnedBlogs[0].blogid);
        }
    }
}
